package adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import java.util.ArrayList;
import java.util.List;

import beans.GoodsDetailInfoBean;
import butterknife.BindView;
import constants.Constants;
import custom.BaseRecyclerAdapter;

/**
 * Created by Administrator on 2018/10/26.
 */

public class GoodsDetailsBarCodeAdapter extends BaseRecyclerAdapter<GoodsDetailsBarCodeAdapter.GoodsDetailsBarViewHolder> {
    private Context mContext;
    private LayoutInflater inflater;
    private List<String> list ;
    public GoodsDetailsBarCodeAdapter(Context mContext,List<String> list) {
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
        this.list = list;
    }

    @Override
    public GoodsDetailsBarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        GoodsDetailsBarViewHolder viewHolder = new GoodsDetailsBarViewHolder(inflater.inflate(R.layout.adapter_goods_detail, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(GoodsDetailsBarViewHolder holder, int position) {
        String s = list.get(position);
        String[] split = s.split(Constants.INCREASE_DECREASE_SPLIT);
        holder.tvBarcode.setText(split[0]);
        if (split.length > 1) {
            holder.tvTimeTitle.setVisibility(View.VISIBLE);
            holder.tvTime.setText(split[1].substring(0,19));
        }else {
            holder.tvTimeTitle.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class GoodsDetailsBarViewHolder extends BaseRecyclerAdapter.BaseViewHolder {

        @BindView(R.id.tv_adapter_goods_detail_barcode)
        TextView tvBarcode;
        @BindView(R.id.tv_adapter_goods_detail_time)
        TextView tvTime;
        @BindView(R.id.tv_adapter_goods_detail_time_title)
        TextView tvTimeTitle;


        public GoodsDetailsBarViewHolder(View itemView) {
            super(itemView);
        }
    }
}
